package com.dhp.bkOjjudgeservice.strategy;

import com.dhp.model.codesandbox.JudgeInfo;
import com.dhp.model.codesandbox.JudgeStrategyContext;
import com.dhp.model.entity.QuestionSubmit;
import com.dhp.model.enums.QuestionSubmitLanguageEnum;
import org.springframework.stereotype.Service;

/**
 * 策略选择管理类
 */
@Service
public class JudgeStrategyManager {
    private static final Long JAVA_EXTRA_TIME = 20L;

    public void doJudge(JudgeStrategyContext judgeStrategyContext){

        JudgeServiceStrategy judgeServiceStrategy = new JudgeServiceStrategy();
        QuestionSubmit questionSubmit = judgeStrategyContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();

        //todo 暂时先只写java的策略 执行时间减去
        if (QuestionSubmitLanguageEnum.JAVA.getValue().equals(language)){
            JudgeInfo judgeInfo = judgeStrategyContext.getJudgeInfo();
            judgeInfo.setTime(judgeInfo.getTime() - JAVA_EXTRA_TIME);
        }

        judgeServiceStrategy.doJudge(judgeStrategyContext);
    }
}
